let uid = 0;

export default class Dep {
    static target = null;

    constructor() {
        this.id = uid++;
        this.subs = [];
    }

    addSub(sub) {
        this.subs.push(sub);
    }

    depend() {
        if (Dep.target) {
            Dep.target.addDep(this);
        }
    }

    notify() {
        const subs = this.subs.slice();

        subs.forEach(sub => {
            sub.update();
        });
    }
}